<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\api\IntermediaryUser;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    public function indexDo(Request $request)
    {
        $id = $request['id'];
        $data = IntermediaryUser::where('id',$id)->first();
        return ['code' => 200, 'msg' => '成功', 'data' => $data];
    }

    public function index()
    {
       $data =  Consult::where('status',1)->orderBy('issue_time','desc')->get()->toarray();
       return $data;
    }

    public function listIndex(Request $request)
    {
        $id = $request->get('id');
        $data = Redis::get($id);
        if (empty($data)){
           $content =  Consult::where('id',$id)->get()->toarray();
           $content = json_encode($content);
           Consult::where('id',$id)->increment('read');
           Redis::set($id,$content,2500);
           return json_encode(['code'=>200,'data'=>$content,'msg'=>'ok']);
        }else{
            $data = Redis::get($id);
            Consult::where('id',$id)->increment('read');
            $data = json_decode($data,true);
            return json_encode(['code'=>200,'data'=>$data,'msg'=>'ok']);
        }
    }
}
